<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * FormativeLab
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		FormativeLab
 * @author		FormativeLab Dev Team
 * @copyright	Copyright (c) 2011 - 2013, FormativeLab, Inc.
 * @license		http://www.formativesoft.com/license/
 * @link		http://www.formativesoft.com/
 * @since		Version 2.0
 * @filesource ./application/modules/m01001/controllers/m01i001/c01i002001.php
 */

// ------------------------------------------------------------------------

/**
 * FormativeLab C01I002001 Controller
 *
 * @package		FormativeLab
 * @subpackage	controllers
 * @category	controllers
 * @author		Formative Soft Ltd
 * @link		http://www.formativesoft.com/
 */

// ------------------------------------------------------------------------

class C01I002001 extends FSL_Controller {

	static $helpers	= array();
	static $models	= array('M01I000001', 'M01I001001', 'M01I002001', 'M01I003001', 'M01I004001', 'M01I005001', 'M01I006001'
					  , 'M01I007001', 'M01I008001', 'M01I009001', 'M01I010001', 'M01I011001', 'M01I012001');

	/**
	 * __construct() Method is an empty constructor. This method use for initialization of 
	 * the controller. This constructor use to load required helpers, model, libraries.
	 *
	 * @access	public
	 * @return  void 
	 **/
	public function __construct(){
        parent::__construct(Renderer::DEFAULTS);
		$this->load->helper(self::$helpers);
		loadModel(self::$models);
    }
	
	/**
	 * create() action use to catch Extjs 4.1 data proxy submited create action. It's read the
	 * json request only for action method POST. Convert json object to Domain/Entity/Model
	 * class object. and validate data to perform insert data into RDMS. On response it send
	 * persisted data with messages whether its persist or not in JSON format.
	 *
	 * @access	public
	 * @return  void 
	 **/
	public function create(){
		if(isPostRequest()){		
			$this->M01I002001->beginTrasaction();	
			$model 		= jsonRequestAsModel('M01I002001');			
			$model->id	= intval(8);
			$model->save(true);			
			$this->M01I002001->commitTrasaction();
		}
	}
	
	/**
	 * read() action use to catch Extjs 4.1 data proxy submited read action. It's read the id
	 * of Entity/Domain/Model and allowed only for request action method GET. It's search the
	 * persist object from RDMS. After peforming query on response its send persist object
	 * as JSON format with messages.
	 *
	 * @access	public
	 * @return  void 
	 **/
	public function read(){
		if(isGetRequest()){
			$id = $this->input->get('id');
			$this->M01I002001->jfindById(intval($id));
		}
	}
	
	/**
	 * update() action use to catch Extjs 4.1 data proxy submited update action. It's read the
	 * json request only for action method PUT. Convert json object to Domain/Entity/Model
	 * class object. and validate data to perform update data into RDMS. On response it send
	 * persisted data with messages whether its persist or not in JSON format.
	 *
	 * @access	public
	 * @return  void 
	 **/
	public function update(){
		if(isPostRequest()){			
			$this->M01I002001->beginTrasaction();	
			$model 		= jsonRequestAsModel('M01I002001');
			$model->update(true);			
			$this->M01I002001->commitTrasaction();
		}
	}
	
	/**
	 * destroy() action use to catch Extjs 4.1 data proxy submited destroy action. It's read the
	 * id of Entity/Domain/Model and allowed only for request action method DELETE. Its search the
	 * persist object from RDMS. if persist object found then it perform delete operation into the
	 * RDMS. After that on response its send destroyed object withe messages whether it's peform
	 * successfully delete or not as JSON format.
	 *
	 * @access	public
	 * @return  void 
	 **/
	public function destroy(){
		if(isPostRequest()){
			$model = jsonRequestAsModel('M01I002001');	
			$this->M01I002001->beginTrasaction();
			$model->destory(true);			
			$this->M01I002001->commitTrasaction();
		}
	}
	
	/**
	 * store() action use to catch Extjs 4.1 data proxy submited read action. It's read the id
	 * or filter properties of Entity/Domain/Model and allowed only for request action method GET.
	 * It's search the persist object from RDMS as the id or properties . After peforming query on
	 * response its send persist object as JSON format with messages.
	 *
	 * @access	public
	 * @return  void 
	 **/
	public function store($offset=0, $limit=10){
		if(isGetRequest()){
			$start = $this->input->get('start');
			$range = $this->input->get('limit');			
			$start = $start ? $start : $offset;
			$range = $range ? $range : $limit;
			$this->M01I002001->jall($range, $start);
		}
	}
	
}

/* End of file c01i002001.php */
/* Location: ./application/modules/m01001/controllers/m01i001/c01i002001.php */